package com.mj.set;

import com.mj.set.file.FileInfo;
import com.mj.set.file.Files;

import javax.xml.stream.FactoryConfigurationError;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    static void test01() {
        Set<Integer> listSet = new ListSet<>();
        listSet.add(11);
        listSet.add(12);
        listSet.add(11);
        listSet.add(13);
        listSet.add(13);
        listSet.add(15);

        listSet.traversal(new Set.Visitor<Integer>() {
            @Override
            boolean visit(Integer element) {
                System.out.println(element);

                return false;
            }
        });
    }

    static void test02() {
        Set<Integer> treeSet = new TreeSet<>();
        treeSet.add(11);
        treeSet.add(12);
        treeSet.add(11);
        treeSet.add(13);
        treeSet.add(13);
        treeSet.add(15);
        treeSet.traversal(new Set.Visitor<Integer>() {
            @Override
            boolean visit(Integer element) {
                System.out.println(element);

                return false;
            }
        });

    }

    static void testSet(Set<String> set, String[] words) {
        for (int i = 0; i < words.length; i++) {
            set.add(words[i]);
        }
        for (int i = 0; i < words.length; i++) {
            set.contains(words[i]);
        }
        for (int i = 0; i < words.length; i++) {
            set.remove(words[i]);
        }
    }

    static void test03() {
        FileInfo fileInfo = Files.read("H:\\src\\java\\util\\concurrent", new String[]{"java"});
        System.out.println("文件数量：" + fileInfo.getFiles());
        System.out.println("代码行数：" + fileInfo.getLines());
        System.out.println("单词数量：" + fileInfo.words().length);
        String[] words = fileInfo.words();

        Times.test("ListSet", () -> testSet(new ListSet<>(), words));
        Times.test("TreeSet", () -> testSet(new TreeSet<>(), words));

    }

    public static void main(String[] args) {
        test03();
    }


}
